{extend name="template/base" /}
{block name="nav"}{/block}
{block name="content"}
<div class="page-container">
    <form class="form form-horizontal" id="updateclass" method="post" action="{:\\think\\Url::build('classAddUpdate')}">
            <input type="text" class="input-text" value="{$class.cid ?? ''}" placeholder="" name="id" " style="width:0;height:0">
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-3"><span class="c-red">*</span>分类名称：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <input type="text" class="input-text" value="{$class.name ?? ''}" placeholder="" name="name" datatype="s" nullmsg="请填写分类名称">
            </div>
            <div class="col-xs-3 col-sm-3"></div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-3">父分类：</label>
            <select class="formControls col-sm-6" id="preclass" name="parent" style="width: 150px;height: 30px" >
                
            </select>
            <div class="col-xs-3 col-sm-3"></div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-3">分类介绍：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <input type="text" class="input-text" value="{$class.introduce ?? ''}" placeholder="" name="introduce" ignore="ignore" >
            </div>
            <div class="col-xs-3 col-sm-3"></div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-3">备注：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <input type="text" class="input-text" value="{$class.remarks ?? ''}" placeholder="" name="remarks" ignore="ignore" >
            </div>
            <div class="col-xs-3 col-sm-3"></div>
        </div>

        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <button type="submit" class="btn btn-primary radius">&nbsp;&nbsp;提交&nbsp;&nbsp;</button>
                <button type="button" class="btn btn-default radius ml-20" onClick="cancelAction();">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
            </div>
        </div>
    </form>
</div>
{/block}
{block name="script"}
<script type="text/javascript" src="__STATIC__/admin/lib/Validform/5.3.2/Validform.min.js"></script>
<!--<script type="text/javascript" src="__STATIC__/admin/js/jquery-2.1.0.min.js"></script>-->
<script>
    $(function () {
        $("#updateclass").Validform({
            tiptype:2,
            ajaxPost:true,
            showAllError:true,
            callback:function(ret){
                if(ret.code){
                    layer.msg(ret.msg);
                }
                else{
                    layer.msg('操作成功',{time:2000},'',location.href = '/index/Product/classShow');
//                    location.href = '{$Request.get.callback ?: \\think\\Url::build("/index/product/classShow")}';
                }
            }
        });
//        window.location.href = "/index/user/show";
    });
    function cancelAction(){
        window.location.href = "/index/product/classShow";
    }
//    $("input[name='gender'][value={$user.gender ?? 1}]").attr("checked",true);
    $.getJSON("/index/product/preClass", function(ret){  
        var html = "";
        var pre = ret.data;  
        html += "<option value=0> --请选择-- </option>";
        if(pre){
          var parent={$class.parent ?? 0};
          for(var i=0; i < pre.length; i++) {  
            var p = pre[i];  
            if(p.preid===parent){
                html += "<option value='" + p.preid + "'selected="+"selected"+">" + p.prename + "</option>";
            }
            else{
                html += "<option value='" + p.preid + "'>" + p.prename + "</option>";
            }
          }  
        }
        $("#paeclass").empty();  
//        $("#preclass option[value={$class.parent ?? 0}]").attr("selected",true);
        $("#preclass").html(function(i,origText){  
//            $("#preclass option[value={$class.parent ?? 0}]").attr("selected",true);
            return html;  
        }); 
    });
//    $("#preclass option[value={$class.parent ?? 0}]").attr("selected",true);
</script>
{/block}